import { get_without_param, post_with_json, delete_with_param, put_with_json } from './HttpMethod';

// 获取规则列表
export function getRules(params: any) {
  const queryString = new URLSearchParams(params).toString();
  return get_without_param(`/api/auto-accounting/rules?${queryString}`);
}

// 创建规则
export function createRule(params: any) {
  return post_with_json('/api/auto-accounting/rules', params);
}

// 更新规则
export function updateRule(id: string, params: any) {
  return put_with_json(`/api/auto-accounting/rules/${id}`, params);
}

// 删除规则
export function deleteRule(id: string) {
  return delete_with_param(`/api/auto-accounting/rules/${id}`);
}

// 切换规则状态
export function toggleRuleStatus(id: string) {
  return put_with_json(`/api/auto-accounting/rules/${id}/toggle-status`, {});
}

// 获取模板列表
export function getTemplates(params: any) {
  const queryString = new URLSearchParams(params).toString();
  return get_without_param(`/api/auto-accounting/templates?${queryString}`);
}

// 创建模板
export function createTemplate(params: any) {
  return post_with_json('/api/auto-accounting/templates', params);
}

// 更新模板
export function updateTemplate(id: string, params: any) {
  return put_with_json(`/api/auto-accounting/templates/${id}`, params);
}

// 删除模板
export function deleteTemplate(id: string) {
  return delete_with_param(`/api/auto-accounting/templates/${id}`);
}

// 获取执行日志
export function getExecutionLogs(params: any) {
  const queryString = new URLSearchParams(params).toString();
  return get_without_param(`/api/auto-accounting/logs?${queryString}`);
}

// 从模板创建规则
export function createRuleFromTemplate(templateId: string, customizations?: any) {
  return post_with_json(`/api/auto-accounting/templates/${templateId}/create-rule`, customizations || {});
}

// 重试执行
export function retryExecution(logId: string) {
  return post_with_json(`/api/auto-accounting/execution-logs/${logId}/retry`, {});
}
